package com.test.spring.controller;

import com.test.spring.service.UserService;
import com.test.spring.util.response.ResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.ExecutionException;

/**
 * Created by ll on 2017/2/15.
 */
@Controller
@RequestMapping
public class APIController {
    private static final Logger LOGGER = LoggerFactory.getLogger(APIController.class);

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/list/master")
    public ResponseEntity<ResponseMessage> getMaterList(){
        return new ResponseEntity<ResponseMessage>(ResponseMessage.success(userService.findMaster()), HttpStatus.OK);
    }

    @ResponseBody
    @RequestMapping(value = "/list/slave")
    public ResponseEntity<ResponseMessage> getSlaveList() throws ExecutionException, InterruptedException {
        return new ResponseEntity<ResponseMessage>(ResponseMessage.success(userService.findSlave()), HttpStatus.OK);
    }

    @ResponseBody
    @RequestMapping(value = "/list/testTransaction")
    public ResponseEntity<ResponseMessage> testTran() throws Exception {
        userService.test();
        return new ResponseEntity<ResponseMessage>(ResponseMessage.success(), HttpStatus.OK);
    }
}

